package com.yantong.controller;

import com.yantong.annotation.Log;
import com.yantong.result.ResultVo;
import com.yantong.utils.PageUtils;
import com.yantong.pojo.ProjectExp;
import com.yantong.pojo.vo.ProjectExpVo;
import com.yantong.service.ProjectExpService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理
 * @author xiangyi
 * @date 2018/9/7.15:39
 */

@Controller
@RequestMapping("/project/exp")
public class ProjectexpController extends BaseController {
    private static final String prefix = "projectexp";
    private static final Logger logger = LoggerFactory.getLogger(ProjectexpController.class);
    @Autowired
    private ProjectExpService projectExpService;
    
    /**
     * 订单列表
     * @param model
     * @return
     */
    @GetMapping()
    @RequiresPermissions("projectexp:manage")
    public String orders(Model model) {
        return prefix + "/projectexp";
    }
    
    
    /**
     * 添加
     * @param model
     * @return
     */
    @GetMapping("/toAddPage")
    @RequiresPermissions("projectexp:manage:add")
    public String toAddPage(Model model) {
        return prefix + "/add";
    }

    
    /**
     * 添加
     * @param model
     * @return
     */
    @GetMapping("/toEditPage/{id}")
    @RequiresPermissions("projectexp:manage:edit")
    public String toEditPage(@PathVariable Long id, Model model) {
    	 ProjectExpVo record = new ProjectExpVo();
    	 record.setId(id);
    	 model.addAttribute("projectExp", projectExpService.listProjectExp(record));
        return prefix + "/edit";
    }


    /**
     * 项目系统模板表数据
     * @param params
     * @param offset
     * @param limit
     * @return
     */
    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("projectexp:manage")
    public PageUtils<ProjectExp> listOrders(ProjectExpVo params, int offset, int limit) {
        return projectExpService.listProjectExp(params, offset, limit);
    }
    
    
    /**
     * 数据保存 修改
     * @return
     */
    @Log(module = "商户版本管理", operation = "新增或编辑")
    @ResponseBody
    @RequiresPermissions("projectexp:manage:add")
    @PostMapping("/saveOrUpdate")
    public ResultVo saveOrUpdate (ProjectExpVo params) {
        if (params == null) {
            return ResultVo.error();
        }
        //添加
       if(params.getId()==null) {
    	   int saveNum =   projectExpService.save(params);
    	   if(saveNum>0) {
    		   return ResultVo.ok();
    	   }else {
    		   return ResultVo.error();
    	   }
       }else {
    	   //修改
    	  int updNum = projectExpService.update(params);
    	  if(updNum>0) {
    		  return ResultVo.ok();
    	  }else {
   		   return ResultVo.error();
   	   }
       }
    }
    
    
    /**
     *删除
     * @return
     */
    @Log(module = "商户版本管理", operation = "删除")
    @ResponseBody
    @RequiresPermissions("projectexp:manage:remove")
    @PostMapping("/remove")
    public ResultVo remove (ProjectExpVo params) {
        if (params == null) {
            return ResultVo.error();
        }
        int  delNum= projectExpService.remove(params);
        if(delNum>0) {
        	return ResultVo.ok();
        }else {
        	return ResultVo.error();
        }
    }

}
